<?php
namespace app\admin\controller\api;

use app\CommonController;


/**
 * 图标选择器
 * @login true
 */
class Plugs  extends CommonController
{
    public function icon()
    {

        // 读取 layui 字体图标
        if (empty($layuiIcons = $this->app->cache->get('LayuiIcons', []))) {
            $style = file_get_contents(WEB_PATH.'/static/admin/plugs/layui/css/layui.css');
            if (preg_match_all('#\.(layui-icon-[\w-]+):#', $style, $matches)) {
                if (count($layuiIcons = $matches[1]) > 0) {
                    $this->app->cache->set('LayuiIcons', $layuiIcons, 60);
                }
            }
        }
        // 读取 ThinkAdmin 字体图标
        if (empty($thinkIcons = $this->app->cache->get('ThinkAdminSelfIcons', []))) {
            $style = file_get_contents(WEB_PATH.'/static/admin/theme/css/iconfont.css');
            if (preg_match_all('#\.(iconfont-[\w-]+):#', $style, $matches)) {
                if (count($thinkIcons = $matches[1]) > 0) {
                    $this->app->cache->set('ThinkAdminSelfIcons', $thinkIcons, 60);
                }
            }
        }
        // 读取 extra 自定义字体图标
        if (empty($extraIcons = $this->app->cache->get('ThinkAdminExtraIcons', []))) {
            $extraIconPath = WEB_PATH.'/static/admin/extra/icon/iconfont.css';
            if (file_exists($extraIconPath)) {
                $style = file_get_contents($extraIconPath);
                if (preg_match_all('#\.(iconfont-[\w-]+):#', $style, $matches)) {
                    if (count($extraIcons = $matches[1]) > 0) {
                        $this->app->cache->set('ThinkAdminExtraIcons', $extraIcons, 60);
                    }
                }
            }
        }
        $this->assign("title","字体列表");
        $this->assign("extraIcons",$extraIcons);
        $this->assign("thinkIcons",$thinkIcons);
        $this->assign("layuiIcons",$layuiIcons);
        $this->assign("field",$this->app->request->get('field', 'icon'));
        return $this->fetch(dirname(__DIR__, 2) . '/view/api/icon.html');
    }
}